<?php
  include __DIR__."/config/cors.php";
  include __DIR__."/database.php";


  $loginusername = @$_POST['loginusername'];
  $loginrole = @$_POST['loginrole'];
  $uid = @$_POST['uid'];
  $role = @$_POST['role'];
  $mail = @$_POST['mail'];
  $status = @$_POST['status'];


  if(!isset($loginusername) or !isset($loginrole)){
    echo json_encode([
        "code" => 202,
        "msg"=> "请管理员登陆后在修改"
      ]);
      exit;
  }

  if(!isset($uid) or !isset($role)or !isset($mail) or !isset($status)){
    echo json_encode([
        "code" => 203,
        "msg"=> "必要参数传递有误"
      ]);
      exit;
  }

    $db = new DB();
    $sql = "update user set role = '$role',mail='$mail',status = '$status' where id = '$uid'";
    if ($db->update($sql)) {
      echo json_encode([
          "code" => 200,
          "msg"=>"修改成功"
      ]);
    } else {
      echo json_encode([
          "code" => 204,
          "msg"=> "修改失败: " . $data
      ]);
    }
?>